//
//  HeadLineDetailController.m
//  Product_NEWS
//
//  Created by dllo on 16/1/8.
//  Copyright © 2016年 FCH. All rights reserved.
//
static CGFloat Height = 30;
#import "HeadLineDetailController.h"
#import "NewsDetailView.h"
#import "NewsDetailModel.h"
#import "NetRequest.h"
#import "FavoriteModel.h"
#import "DataHandle.h"
#import "UMSocialSnsPlatformManager.h"
#import "UMSocialSnsService.h"
#import "CommentController.h"
@interface HeadLineDetailController ()
@property(nonatomic,retain)NewsDetailView *rootView;
@property (nonatomic, retain) MBProgressHUD *hud;
@end

@implementation HeadLineDetailController


- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self createwebView];
    [self initUI];
  
}

-(void)loading{
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    self.hud.dimBackground = YES;
    
    [self.hud showAnimated:YES whileExecutingBlock:^{
        [self createwebView];
        
        self.hud.labelText = @"加载中";
        
    }];
    
    [self.view addSubview:self.hud];
    
}


-(void)initUI
{
     self.rootView = [[[NewsDetailView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
    [self.view addSubview:self.rootView];
     self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.956 alpha:1.000];
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100 * SCREEN_WIDTH, Height )];
    customLab.backgroundColor = [UIColor clearColor];

    [customLab setText:@"新闻详情"];
    customLab.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = customLab;
    [customLab release];
    self.navigationController.navigationBar.translucent = NO;

   
    
    
    
    [_rootView.btnComment addTarget:self action:@selector(handleClick:) forControlEvents:UIControlEventTouchUpInside];
    [_rootView.btnSave addTarget:self action:@selector(handleSave:) forControlEvents:UIControlEventTouchUpInside];
    [_rootView.btnShare addTarget:self action:@selector(handleShare:) forControlEvents:UIControlEventTouchUpInside];
    
}



#pragma mark -- action



//评论
- (void)handleClick:(UIButton *)sender {
    CommentController *commentController = [[CommentController alloc] init];
    commentController.docid = self.docid;
  
  
    commentController.flag = self.flag; //评论标识
    
      NSLog(@"%@",commentController.docid);
      NSLog(@"%@",commentController.flag);
    
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:commentController animated:YES];
    [commentController release];
}


//收藏
- (void)handleSave:(UIButton *)sender {
    FavoriteModel *model = [[FavoriteModel alloc]init];
    model.fchtitle = self.newsTitle;
    model.fchurl = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/%@/full.html",self.docid];
    model.fchdocid = self.docid;
    model.flag = @"NEWS";
    model.fchboardid = self.flag;
    MBProgressHUD *hud = [[MBProgressHUD alloc]init];
    [self.view addSubview:hud];
    if ([DataHandle insertData:model ]) {
        hud.labelText = @"收藏成功";
    }else{
      hud.labelText = @"已经收藏";
    }
    
    hud.dimBackground = YES;
    hud.mode = MBProgressHUDModeText;
    [hud showAnimated:YES whileExecutingBlock:^{
        sleep(1);
    } completionBlock:^{
        [hud removeFromSuperview];
    }];
    [hud release];
    [model release];
}

//分享
- (void)handleShare:(UIButton *)sender{
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    /**
     Sns平台类，用`platformName`作为标识，指定显示名称、显示的图片，点击之后的响应。
     */
    snsPlatform.displayName = @"新浪";
    snsPlatform.loginName = @"网易";
    
    
    UMSocialSnsPlatform *snsPlatform2 = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToTencent];
    snsPlatform2.displayName = @"腾讯微博";
    
    
    
    //分享第二步
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"558936d367e58eb81b001298"
                                      shareText:@"你要分享的文字"
                                     shareImage:[UIImage imageNamed:@"Icon-29.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
                                       delegate:nil];
    
    
    
    
}








-(void)createwebView{
    NetRequest *net = [[NetRequest alloc]init];
    [net GET:[ NSString stringWithFormat:@"http://c.3g.163.com/nc/article/%@/full.html",self.docid] completion:^(id operation, id respObj, NSError *error) {
        NSDictionary *dataDict = respObj[self.docid];
        NewsDetailModel *model= [NewsDetailModel new];
        [model setValuesForKeysWithDictionary:dataDict];
       self.rootView.model = model;
}];
    
  
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
